<%@page import="com.kensure.shike.constant.BusiConstant"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<jsp:include page="base/header.jsp" flush="true"> 
 <jsp:param value="类型编辑" name="pageTitle"/>
</jsp:include>
<style>
	.pic{width:180px;height:180px;}
</style>

<body>


<style>
.mainweb{ 
	width:100%; 
	height:100%; 
	overflow:auto; 
} 
.btop{
	position:absolute; 
	top:10px; 
	right:16px; 
	width:100px; 
	height:100px; 
}
</style>

<div style="padding: 15px;" class="mainweb layui-anim layui-anim-upbit">
	
	<fieldset class="layui-elem-field">
		<legend>类型编辑</legend>
		<div class="layui-field-box">
		    <form id="editForm" class="layui-form" lay-filter="form">
			   
			     <div class="layui-form-item">
					<label class="layui-form-label">名称</label>
					<div class="layui-inline">
						<input type="text" name="name" style="width:600px;" class="layui-input" value="">
					</div>
				</div>
				
				<div class="layui-form-item">
					<label class="layui-form-label">备注</label>
					<div class="layui-inline">
						<input type="text" name="remark" style="width:600px;" class="layui-input" value="">
					</div>
				</div>
				
				 <div class="layui-form-item" id="fenlei">
					<label class="layui-form-label">分类</label>
			     	<input name='pid' type='radio' title='无' value='0'>
			    </div>	
	
				<div class="layui-form-item">
					<label class="layui-form-label">排序(越小越排前面)</label>
					<div class="layui-inline">
						<input type="text" name='disorder' class="layui-input" value="">
					</div>
				</div>
				
				 <div class="layui-form-item">
					<label class="layui-form-label">图片</label>
					  <div class="layui-inline">
						<img class="picurl" id="picurl" onclick="uploadpic(this)" style="width:100px;height:100px;" src="<%=BusiConstant.context%>/common/images/no_pic.jpg">
					</div>
				</div>
		        
		    </form>
		 </div>
	</fieldset>		
</div>

 	<div id="dg" class="proll">
		<div class="divroll">
				<button id="btn1" onclick="savebaobei()"  class="layui-btn layui-btn-normal">保存</button>
				
		</div>
	</div>

</body>




<script>
    
    var id = getQueryVariable("id");
   //JavaScript代码区域，layui初始化
	layui.use(['element', 'layer', 'form', 'laydate', 'upload'], function(){
		var $ = layui.jquery;
		var element = layui.element;
		var layer = layui.layer;
		var form = layui.form;
		var laydate = layui.laydate,
			upload = layui.upload;	
		
		
	    if(id){
	    	var url = getbaseurl("/type/get.do");
	    	var data = {id:id};
	    	postsync(url, data, function(data){
				var row = data.resultData.row;
				row.pid = row.pid+"";
				if(row.picurl){
					$('#picurl').attr("src",row.picurl);
				}
				form.val('form',row);
				form.render();
			}, null, null);
	    }
	});
	
	function uploadpic(obj){
		//上传图
		uploadImage(function(p) {
			var rows = p.resultData.rows;
			$.each(rows, function(i, row){
			      $(obj).attr("src",row);
			});
		}, false);
	}
	
	// 保存
	var baocun = false;
	function savebaobei() {
		if (baocun) {
			alert("请勿重复保存");
		}	
		baocun = true;
		var data = formtojson($('#editForm'));
		if(id){
			data.id = id;
		}
		var picurl = $('#picurl').attr("src");
		if(picurl.indexOf('no_pic.jpg') == -1){
			data.picurl = picurl;
		}	
		var url = getbaseurl("/type/save.do");
		postdo(url, data, function(data){
			alert("保存成功")
			var mylay = parent.layer.getFrameIndex(window.name);
            parent.layer.close(mylay);
            window.parent.doSearch();
		}, null, svcompdo);
	}
	
	function svcompdo(data) {
		baocun = false;
	}
	
     
</script>


</html>